package com.hazardSoft.eStore.ejb;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.hazardSoft.eStore.bussines.UsersBO;
import com.hazardSoft.eStore.common.exception.SystemException;
import com.hazardSoft.eStore.entities.User;
import com.hazardSoft.eStore.interfaces.UsersLocal;

/**
 * Session Bean implementation class UsersEJB
 */
@Stateless
public class UsersEJB implements UsersLocal {

	public static final String EJB_NAME = UsersEJB.class.getSimpleName()+"Local";
	
	@PersistenceContext(unitName = "EStoreJPA")
	private EntityManager entityManager;
	private UsersBO usersBO;
	
    /**
     * Default constructor. 
     */
    public UsersEJB() {
        usersBO = new UsersBO();
    }

	/**
     * @throws SystemException 
	 * @see UsersLocal#removeUser(User)
     */
    public boolean removeUser(User user) throws SystemException {
 
		return usersBO.removeUser(user, entityManager);
    }

	/**
     * @throws SystemException 
	 * @see UsersLocal#authenticateUser(User)
     */
    public User authenticateUser(User user) throws SystemException {
        
		return usersBO.authenticateUser(user, entityManager);
    }

	/**
     * @throws SystemException 
	 * @see UsersLocal#updateUser(User)
     */
    public User updateUser(User user) throws SystemException {
        
		return usersBO.updateUser(user, entityManager);
    }

	/**
     * @throws SystemException 
	 * @see UsersLocal#searchUserByLogin(User)
     */
    public User searchUserByLogin(User user) throws SystemException {
        
		return usersBO.searchUserByLogin(user, entityManager);
    }

	/**
     * @throws SystemException 
	 * @see UsersLocal#insertUser(User)
     */
    public User insertUser(User user) throws SystemException {
        
		return usersBO.insertUser(user, entityManager);
    }

	/**
     * @throws SystemException 
	 * @see UsersLocal#listUsers()
     */
    public List<User> listUsers() throws SystemException {
        
		return usersBO.listUsers(entityManager);
    }

	/**
     * @throws SystemException 
	 * @see UsersLocal#searchUserById(User)
     */
    public User searchUserById(User user) throws SystemException {
        
		return usersBO.searchUserById(user, entityManager);
    }

	public User getBillsBySeller(User seller) throws SystemException {
		
		return usersBO.getBillsBySeller(seller, entityManager);
	}

}
